package h0802;

import java.util.Arrays;
import java.util.Scanner;
import java.util.function.ToIntFunction;

/**
  * @description 最大股票收益
  * @author 不知名帅哥
  * @date 2024/8/2 18:59
  * @version 1.0
*/
public class MaxStockFit {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int[] stocks = Arrays.stream(sc.nextLine().split(" ")).mapToInt(value -> {
            int n = value.length();
            char last = value.charAt(n - 1);
            String substring = value.substring(0, n - 1);
            int i = Integer.parseInt(substring);
            if (last == 'Y') {
                return i;
            } else {
                return i * 7;
            }
        }).toArray();
        int res=getMaxFit(stocks);
        System.out.println(res);
    }

    private static int getMaxFit(int[] stocks) {
        int i=0;
        int j=1;
        int n = stocks.length;
        int ans=0;
        //只买上升区段
        while (i<n&&j<n){
            if (stocks[i]<stocks[j]){
                ans+=stocks[j]-stocks[i];
            }
            i++;
            j++;
        }
        return ans;
    }
}
